package com.zzq.subservice.impl;

import com.zzq.annotation.SubService;
import com.zzq.domain.dto.SmilePointRuleDTO;
import com.zzq.domain.entity.SmileClient;
import com.zzq.domain.entity.SmilePointRecord;
import com.zzq.enumerate.IncomeExpenditureStatusEnum;
import com.zzq.enumerate.PointSourceTypeEnum;
import com.zzq.security.util.UserUtil;
import com.zzq.service.SmileClientService;
import com.zzq.service.SmilePointRuleService;
import com.zzq.service.impl.SmilePointRecordServiceImpl;
import com.zzq.subservice.EarnPointsSubService;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * 积分服务
 */
@SubService
public class EarnPointsSubServiceImpl implements EarnPointsSubService {

    @Autowired
    SmilePointRecordServiceImpl pointRecordService;
    @Autowired
    SmilePointRuleService pointRuleService;
    @Autowired
    SmileClientService clientService;
    @Override
    public SmilePointRecord expensesPoints(Long clientId, String clientNo, Integer points, String remark,Long pointsSourceId) {
        SmilePointRecord record=new SmilePointRecord();
        record.setClientId(clientId);
        record.setClientNo(clientNo);
        record.setPoints(points);
        record.setRemark(remark);
        record.setPointsSourceId(pointsSourceId);
        record.setIncomeExpenditureStatus(IncomeExpenditureStatusEnum.EXPENSES.getName());
        pointRecordService.save(record);
        return record;
    }

    @Override
    public SmilePointRecord incomePoints(Long clientId, String clientNo, Integer points, String remark,Long pointsSourceId) {
        SmilePointRecord record=new SmilePointRecord();
        record.setClientId(clientId);
        record.setClientNo(clientNo);
        record.setPoints(points);
        record.setRemark(remark);
        record.setPointsSourceId(pointsSourceId);
        record.setIncomeExpenditureStatus(IncomeExpenditureStatusEnum.INCOME.getName());
        pointRecordService.save(record);
        return record;
    }

    @Override
    public SmilePointRecord cheakPoints(Long clientId, String clientNo) {
        SmilePointRuleDTO pointRule = pointRuleService.getPointRuleDTOByType(PointSourceTypeEnum.CHECK.getName());
        Long pointRuleId = pointRule.getPointRuleId();
        return incomePoints(clientId,clientNo,5,"签到",pointRuleId);
    }

    @Override
    public SmilePointRecord buyPoints(Long clientId, String clientNo, Integer goodsPointNum,String CouponNo) {
        SmilePointRuleDTO pointRule = pointRuleService.getPointRuleDTOByType(PointSourceTypeEnum.BUY.getName());
        Long pointRuleId = pointRule.getPointRuleId();
        return expensesPoints(clientId,clientNo,goodsPointNum,"优惠券："+clientNo,pointRuleId);
    }

    @Override
    public SmilePointRecord prizePoints(Long clientId, String clientNo, Integer goodsPointNum) {
        SmilePointRuleDTO pointRule = pointRuleService.getPointRuleDTOByType(PointSourceTypeEnum.PRIZE.getName());
        Long pointRuleId = pointRule.getPointRuleId();
        return incomePoints(clientId,clientNo,goodsPointNum,"盲盒",pointRuleId);
    }

    @Override
    public SmilePointRecord downloadPhotoPoints(Long clientId, String clientNo, Integer photoSize) {
        SmilePointRuleDTO pointRule = pointRuleService.getPointRuleDTOByType(PointSourceTypeEnum.DOWNLOAD_PHOTO.getName());
        Integer pointsUnit=1;
        Integer pointsNum=pointsUnit*photoSize;
        Long pointRuleId = pointRule.getPointRuleId();
        return incomePoints(clientId,clientNo,pointsNum,"下载相册积分",pointRuleId);
    }


}
